package net.dodoman.hash;

import java.util.HashMap;
import java.util.Map;

public class Student {

	private String number;

	private String name;

	private Student(String number, String name) {
		this.number = number;
		this.name = name;
	}

	public boolean equals(Object object) {
		if (object == null) {
			return false;
		}
		if (!(object instanceof Student)) {
			return false;
		}
		Student that = (Student) object;
		return this.number.equals(that.number) && this.name.equals(that.name);
	}

	public int hashCode() {
		int hash = 1; // 任意质数
		hash = hash * 31 + number.hashCode();
		hash = hash * 31 + (number == null ? 0 : number.hashCode());
		return hash;
	}

	public static void main(String[] args) {
		
		Student A = new Student("001", "yangqiang");
		Student sameA = new Student("001", "yangqiang");

		Map<Student, String> map = new HashMap<Student, String>();
		map.put(A, "");
		boolean isConKey = map.containsKey(sameA);
		System.out.println(isConKey);
		
	}
}